home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 2009 Bui Viet Thanh (thanhbv@gmail.com).
- *
- * This file is part of clicknlearn.
- *
- * clicknlearn is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * clicknlearn is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with clicknlearn. If not, see <http://www.gnu.org/licenses/>.
- */
-
- let EXPORTED_SYMBOLS = ["CNL_Prefs"];
-
- const Cc = Components.classes;
- const Ci = Components.interfaces;
-
- /**
- * See prefarray.js in http://mozilla.doslash.org/prefutils/
- * Ohhhhhh! After almost finished, I discover that resource://weave/ext/Preferences.js
- * has implemented a very powerful solution for storing preferences
- */
- var CNL_Prefs = new function(){
- this.prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService)
- .getBranch("extensions.clicknlearn.dicservices.");
-
- this.setDicsArrayPref = function(arr) {
- this.prefBranch.deleteBranch("");
- for(var i in arr)
- for(j in arr[i]){
- let string = Cc["@mozilla.org/supports-string;1"].
- createInstance(Ci.nsISupportsString);
- string.data = arr[i][j];
- this.prefBranch.setComplexValue(i + "." + j, Ci.nsISupportsString, string);
- }
- }
-
- this._getDicsArrayPref = function() {
- var result = [];
- var items = this.prefBranch.getChildList("", {});
- for(var i in items) {
- var path = items[i].split(".");
- var lastIdx = path.length - 1;
- var node = result;
- for(var j in path) {
- if(!(path[j] in node)) {
- if(j != lastIdx)
- node[path[j]] = [];
- else
- node[path[j]] = this.prefBranch.getComplexValue(items[i], Ci.nsISupportsString).data;
- }
- node = node[path[j]];
- }
- }
- return result;
- }
- /**
- * see http://code.google.com/p/clicknlearn/issues/detail?id=19#c5
- */
- this.getDicsArrayPref = this._getDicsArrayPref;/*function() {
- var dicts = this._getDicsArrayPref();
- if(dicts.length == 0)
- dicts =
- [['true', 'tratu.vn', 'http://tratu.vn/dispatchaddon.php?dict=en_vn&title=',
- '<i>Bạn đang tra từ', '']
- ,['true', 'edictx.com', 'http://edictx.com/edictx/?dict=1&mode=addon&word=',
- ' was not found!<', '']
- ,['true', 'tudientiengviet.net', 'http://www.tudientiengviet.net/get.php?mode=quickdict&dict=en-vi&word=',
- 'Các từ tương tự: <br><ul>', '']
- ,['true', 'vdict.com', 'http://vdict.com/fsearch.php?dictionaries=eng2vie_vie2eng_foldoc&word=',
- ' <!-- Database --><!-- Database --><!-- Database -->Not Found.', '']];
- return dicts;
- }*/
- }
-